package com.goodving.guli.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.goodving.guli.R;
import com.goodving.guli.bt.C0668a;
import com.goodving.guli.bt.model.PersonInfo;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.bt.profile.scale.ScaleWeightInfo;
import com.goodving.guli.bt.ui.DimPanelBottomBar;
import com.goodving.guli.model.Keeper;
import com.goodving.guli.view.C3247b;
import com.goodving.guli.view.C3657a;

/**
 * Created by john on 2015/12/9.
 */
public class MemberInfoSetGenderActivity extends MemberInfoBaseActivity implements View.OnClickListener {
    private ImageView f11405h;
    private ImageView f11406i;
    private TextView f11407j;
    private View f11408k;
    private DimPanelBottomBar f11409l;
    private int f11410m;
    private boolean f11411n;

    public MemberInfoSetGenderActivity() {
        this.f11410m = -1;
        this.f11411n = false;
    }

    private void m15817a(int i) {
        if (i == 1) {
            this.f11405h.setImageResource(R.drawable.male_enable);
            this.f11406i.setImageResource(R.drawable.female_disable);
            this.f11408k.setBackgroundResource(R.color.bg_color_blue_dark);
            applyStatusBarTintRes(R.color.bg_color_blue_dark);
            this.f11409l.m14980a(getResources().getColor(R.color.content_color));
            this.f11409l.m14983b(getResources().getColor(R.color.title_color));
            this.f11409l.m14982b().setClickable(true);
        } else if (i == 0) {
            this.f11406i.setImageResource(R.drawable.female_enable);
            this.f11405h.setImageResource(R.drawable.male_disable);
            this.f11408k.setBackgroundResource(R.color.bg_color_red);
            applyStatusBarTintRes(R.color.bg_color_red);
            this.f11409l.m14980a(getResources().getColor(R.color.content_color));
            this.f11409l.m14983b(getResources().getColor(R.color.title_color));
            this.f11409l.m14982b().setClickable(true);
        } else {
            this.f11409l.m14980a(getResources().getColor(R.color.content_color));
            this.f11409l.m14983b(getResources().getColor(R.color.disable_text_color_dark));
            this.f11409l.m14982b().setClickable(false);
        }
    }

    public void onConfirm () { //m15818d

        GuliLog.tracePrintInfo("MemberInfoBaseActivity", "set gender " + this.f11410m);
        if (!this.isVisitorMode) {
            super.onConfirm();
        }
        if (this.f11410m == 1 || this.f11410m == 0) {
            Keeper.saveCurrentUser(Keeper.CURRENT_USER_GENDER, this.f11410m + C3657a.f18328f);
            // here i need to check if this is for person info
            PersonInfo personInfo = Keeper.readPersonInfo();
            if (personInfo.nickname.equals(Keeper.getCurrentUserInfoByTag(Keeper.CURRENT_USER_NAME)) &&
                    String.valueOf(personInfo.uid).equals(Keeper.getCurrentUserInfoByTag(Keeper.CURRENT_USER_ID))) {
                // we need to get all these information
                personInfo.gender = this.f11410m;
                Keeper.keepPersonInfo(personInfo);
            }
            Intent intent = new Intent();
            intent.setClass(this, MemberInfoSetBirthActivity.class);
            intent.putExtra(MemberInfoBaseActivity.setVisitorMode, this.isVisitorMode);
            intent.putExtra(MemberInfoBaseActivity.weightChooseUser, this.isWeightChooseUser);
            intent.putExtra("FROM_BABY_WEIGHT", this.f11411n);
            intent.putExtra(ScaleWeightInfo.WEIGHTADVDATA_KEY, this.f11393g == null ? C3657a.f18328f : this.f11393g.m25503n());
            startActivityForResult(intent, 6);
            return;
        }
        C3247b.m22928a((Context) this, (int) R.string.please_input_gender, 0).show();
    }

    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.info_gender_male:
                this.f11410m = 1;
                m15817a(this.f11410m);
                break;
            case R.id.info_gender_female:
                this.f11410m = 0;
                m15817a(this.f11410m);
                break;
        }
        super.onClick(view);
    }

    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        this.isVisitorMode = getIntent().getBooleanExtra(MemberInfoBaseActivity.setVisitorMode, false);
        this.isWeightChooseUser = getIntent().getBooleanExtra(MemberInfoBaseActivity.weightChooseUser, false);
        this.f11411n = getIntent().getBooleanExtra("FROM_BABY_WEIGHT", false);
        if (!(getIntent() == null || getIntent().getExtras() == null)) {
            this.f11393g = ScaleWeightInfo.m25479b(getIntent().getStringExtra(ScaleWeightInfo.WEIGHTADVDATA_KEY));
        }
        setContentView((int) R.layout.activity_person_info_set_gender);
        m15808b();
        this.f11405h = (ImageView) findViewById(R.id.info_gender_male);
        this.f11405h.setOnClickListener(this);
        this.f11406i = (ImageView) findViewById(R.id.info_gender_female);
        this.f11406i.setOnClickListener(this);
        this.f11407j = (TextView) findViewById(R.id.bracelet_login_title_info);
        this.f11407j.setText(getString(R.string.input_precise_user_info));
        this.f11409l = (DimPanelBottomBar) findViewById(R.id.bottom_bar);
        this.f11408k = findViewById(R.id.info_gender_bg);
        String currentUserInfoByTag = Keeper.getCurrentUserInfoByTag(Keeper.CURRENT_USER_GENDER);
        if (!currentUserInfoByTag.isEmpty()) {
            this.f11410m = Integer.parseInt(currentUserInfoByTag);
        }
        m15817a(this.f11410m);
    }

    protected void onPause() {
        super.onPause();
        C0668a.m8141b(C0668a.aN);
        C0668a.m8138b((Activity) this);
    }

    protected void onResume() {
        super.onResume();
        C0668a.m8133a(C0668a.aN);
        C0668a.m8124a((Activity) this);
    }
}
